package com.glsc.ngateway.common.base.repo.mysql.gateway.platform;


import com.glsc.ngateway.common.base.domain.mysql.gateway.platform.flow.FlowFormSystemNameModify;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Repository;

import javax.validation.constraints.NotBlank;
import java.util.List;

@Repository
public interface FlowFormSystemNameModifyRepo extends JpaRepository<FlowFormSystemNameModify, Long>, JpaSpecificationExecutor<FlowFormSystemNameModify> {
    /**
     * 根据流程Id检索表单
     */
    FlowFormSystemNameModify findByProcessId(@NotBlank String processId);
    /**
     * 根据系统编号查询流程列表
     * @param systemClassNo
     * @return
     */
    List<FlowFormSystemNameModify> findBySystemClassNo(@NotBlank String systemClassNo);

    /**
     * 根据系统编号查询流程列表
     * @param systemClassNo
     * @return
     */
    List<FlowFormSystemNameModify> findBySystemClassNoAndIsCloseEquals(@NotBlank String systemClassNo, @NotBlank Integer isClose);
    /**
     * 统计系统名称数量
     */
    @Query(value = "select count(*) from t_gw_flow_form_system_name_apply " +
            "where deleted = 0 " +
            "and op_name = :opName " +
            "and if ( :id is not null, id != :id , 1 = 1 ) " +
            "and if ( :status is not null, status != :status , 1 = 1 ) " +
            "", nativeQuery = true)
    Integer countByOpNameAndIdNotAndStatusNot(@NotBlank @Param("opName") String opName, @Nullable @Param("id") Long id, @Param("status") String status);

    @Query(value = "select * from t_gw_flow_form_system_name_apply " +
            "where deleted = 0 " +
            "and op_name = :opName " +
            "and if ( :id is not null, id != :id , 1 = 1 ) " +
            "and if ( :status is not null, status != :status , 1 = 1 ) " +
            "", nativeQuery = true)
    List<FlowFormSystemNameModify> findAllByOpNameAndIdNotAndStatusNot(@NotBlank @Param("opName") String opName, @Nullable @Param("id") Long id, @Param("status") String status);

    List<FlowFormSystemNameModify> findAllByProcessId(String processId);
}
